package flc.ast.adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.AppUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.MyAppBean;
import flc.ast.bean.MyReplaceBean;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class AllReplaceAdapter extends StkProviderMultiAdapter<MyReplaceBean> {

    public AllReplaceAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(150));
        addItemProvider(new AllReplaceProvider());
    }


    private class AllReplaceProvider extends BaseItemProvider<MyReplaceBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_replace;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, MyReplaceBean bean) {
            baseViewHolder.setIsRecyclable(false);
            Glide.with(baseViewHolder.itemView).load(bean.getImg()).into((ImageView) baseViewHolder.getView(R.id.ivIconSrc));
            if (bean.getBean()!=null){
                baseViewHolder.setImageDrawable(R.id.ivChooseImage,AppUtils.getAppIcon(bean.getBean().getName()));
                bean.setName(AppUtils.getAppName(bean.getBean().getName()));
            }
            EditText et=baseViewHolder.getView(R.id.etName);
            et.setText(bean.getName());
            et.addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    bean.setName(s.toString());
                }

                @Override
                public void afterTextChanged(Editable s) {

                }
            });
        }
    }
}
